// 2017-10-20 chenym
(function($) {

    $(function() {
        var $exportbtn = $("#exportbtn"),
            $submit = $("#submit"),
            $eatList = $("#eat-list"),
            $userName = $("#user_name"),
            $menuName = $("#menu_name"),
            $price = $("#price"),
            $msgTip = $("#msgTip");
  
            // 导出订单
        	$exportbtn.click(function(){
				window.location.href = webHost + '/order/export';
			});
        	//提交订单
			$submit.click(function(){
				var userName = $userName.val();
				var menuName = $menuName.val();
				var price = $price.val();
				var msg = "";

				getOrderList();
				return ;
				if (userName == "")  {
					msg += "用户名不能为空<br/>";
				}
				if (menuName == "")  {
					msg += "菜单不能为空<br/>";
				}
				if (price == "")  {
					msg += "价格不能为空<br/>";
				}
				if (isNaN(price)) {
					msg += "价格应为数字格式<br/>";
				}
				if(msg != "") {
					$msgTip.html(msg);
	                $msgTip.show();
					return
				}else{
					$msgTip.hide();
				}

				$.ajax({
	                type: 'POST',
	                url: webHost + '/order/order',
	                data: {user_name : userName, menu_name : menuName, price: price},
	                success: function(data) {
	                    console.log(data);
	                    $msgTip.html(data.message);
	                    $msgTip.show();
	                    if(data.status == 1) {
	                    	getOrderList();
	                    } 
	                    setTimeout(function () { 
						    $msgTip.hide();
						}, 5000);
	                },
	                error: function(data) {
	                    console.log("读取jsonName error!");
	                }
	            });
			});
		});

        //获取订单列表
        function getOrderList() {
        	var $eatList = $("#eat-list");
        	var $pricebox = $("#pricebox");

			$.ajax({
	                type: 'get',
	                url: webHost + '/order/tmp',
	                data: {},
	                success: function(data) {
	                    console.log(data);
	                    if(data.status == 1) {
	                    	var html = "";
	                    	var list = data.data;
	                    	var price = 0;
	                    	var total = 0;
	                    	html += '<li>';
				    		html += '<span class="name">姓名</span>';
				    		html += '<span class="name">菜名</span>';
				    		html += '<em class="price">价格</em>';
				    		html += '<span>下单时间</span>';
				    		html += '</li>';
	                    	for (var i=0; i< list.length; i++) {
	                    		html += '<li>';
					    		html += '<span class="name">'+list[i].userName+'</span>';
					    		html += '<span class="name">'+list[i].menuName+'</span>';
					    		html += '<em class="price">￥'+list[i].price+'</em>';
					    		html += '<span>'+list[i].orderTime+'</span>';
					    		html += '</li>';
					    		price += list[i].price;
					    		total += list[i].price;
	                    	}
	                    	$eatList.html(html);
	                    	var boxhtml = '总价：<i>'+data.totalPrice+'</i>元（不含运费）（<em>'+data.total+'</em>）份'
	                    	$pricebox.html(boxhtml);
	                    }
	                },
	                error: function(data) {
	                    console.log("读取jsonName error!");
	                }
	            });
		}
})(jQuery);


//登录按钮变色
/*$(function () {
    $(".input_login").hover(
  function () {
      $(this).addClass("input_loginhover");
  },
  function () {
      $(this).removeClass("input_loginhover");
  });
});*/

